#!/usr/bin/env python
from os import path
import sys

# Get the input file, which should be a racecar data file.
inputFile = sys.argv[1];
inputFileName = path.splitext(path.split(inputFile)[1])[0]

# Does the input exist?
# Test for sanity of parameters. 
if ((inputFile == "") or (path.isfile(inputFile) == False)):
  print "Invalid input file.\n";
  exit(1);

# Format the output file name. 
outputFile = (inputFileName + "_racecar") + ".txt";

# Simply drop the 2nd and 3rd rows from the Orange file, and we're all set.
# Might as well check to make sure they're not continuous while we are at it.
inf = open(inputFile,"r");
outf = open(outputFile,"w");

# Reads first line and writes it to the new file. 
outf.write(inf.readline());

# Parse the next line to check for continuous attributes.
for e in inf.readline():
  if e == "continuous" or e == "c":
    raise ValueError, "Cannot use continuous attributes in a racecar data file.";

# Drop the 3rd line, it is useless.
inf.readline();

# Now just write everything to the output file.
for line in inf:
  outf.write(line);
  
# Close 'em.
inf.close();
outf.close();